# https://mail.qq.com/
from time import sleep
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.support.ui import Select

# 准备options

options = webdriver.ChromeOptions()
user_data_dir = r'--user-data-dir=C:\Users\桂伊凡\AppData\Local\Google\Chrome\User Data\Default'
options.add_argument(user_data_dir)

#打开浏览器设置options，请求网站
driver = webdriver.Chrome(options=options)
driver.get('https://mail.163.com/')

# 定位发邮箱
sleep(2)
driver.find_element(By.XPATH,'//*[@id="_mail_component_149_149"]/span[2]').click()

# 定位收件人输入框
sleep(2)
driver.find_element(By.CLASS_NAME,'nui-editableAddr-ipt').send_keys('1806807989@qq.com') #//*[@id="_mail_emailcontainer_0_271"]

# 定位主题输入框
sleep(2)
driver.find_element(By.XPATH,'/html/body/div[2]/div[1]/div[2]/div[1]/section/header/div[2]/div[1]/div/div/input').send_keys('一个爱你的人')

# 切换窗口
AA = driver.find_element(By.CLASS_NAME,'APP-editor-iframe')
driver.switch_to.frame(AA)

# 用select 定义字体
# sleep(2)
# select = driver.find_element(By.XPATH,'//*[@id="_mail_editor_0_277"]/div[1]/div[1]/div/a[6]/span[1]/b')
#选择 options 字体大写
# sleep(2)
# select.find_element(By.CLASS_NAME,'nui-menu-item-link').click()
# 定义字体大小
# select =driver. find_element(By.CLASS_NAME,'ico ico-editor ico-editor-fontsize')
# select.find_element(By.XPATH,'//*[@id="_mail_menuitem_28_410"]/div/span[2]').click()

# 写信
sleep(2)
driver.find_element(By.XPATH,'/html/body').send_keys('我要和你生猴子')

# 回到父级页面
sleep(2)
driver.switch_to.parent_frame()

# 点击发送
driver.find_element(By.XPATH,'/html/body/div[2]/div[1]/div[2]/div[1]/section/footer/div[1]/span[2]').click()

# 退出浏览器
sleep(4)
driver.quit()





